package com.sanyue;

import com.sanyue.springboot.bean.People;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 修改默认包的扫描结构
 * @author: Guan
 * 路径在sanyue包下，不在MainApp所在包springboot及其子包下，所以默认机制springbbot无法扫描到该类
 *
 **/


@Slf4j //lombok
@Controller
public class HiController {

    //需求分析:属性值从application.properties的k-v
    // @Value("${my.website}")
    private String webSite;

    //自动装配——Spring
    @Resource
    private People people;


    @RequestMapping("/hi")
    @ResponseBody
    public String hello(){
        System.out.println("hi everyone");
        System.out.println("--666--"+webSite);
        return "hi,i am san yue";
    }


    @RequestMapping("/people")
    @ResponseBody
    //返回json类型数据时别忘了添加注解@ResponseBody
    public People FindG(){

        //使用Slf4j日志输出
        //普通方式
        log.info("people-"+people);
        //占位符方式输出
        log.info("people={},myP={}",people,people);
        return this.people;
    }
}
